
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>修改用户信息</title>
<link rel="stylesheet" type="text/css" href="../../Resours/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../../Resours/css/User.css">
</head>
<body>
<div id="head">
	
</div>
<div id="center">
<table class="table table-bordered table-hover" >
	<tbody>
	
	</tbody>
</table>
<button  class="btn btn-primary btn-sm" onclick="update()">确认修改</button>
</div>
<script src="../../Resours/js/jquery-3.3.1.min.js"></script>
<script >
function fun1() {
    
	 var bodys='';
           //发送ajax请求
           $.get("/Shopx/UserServlet?action=user",function (data) {
        	   bodys+=`
        		   <tr>
              		<td>用户名</td>
              		<td>
              			<input type="text" value="${data.u_name}" name="name" id="name"/>
              		</td>
	              	</tr>
	              	<tr>
	              		<td>电话号码</td>
	              		<td>
	              		<input type="text" value="${data.u_phone}" name="phone" id="phone"/>
	              		</td>
	              	</tr>
	              	<tr>
	              		<td>地址</td>
	              		<td>
	              		<input type="text" value="${data.u_address}" name="addr" id="addr"/>
	              		</td>
	              	</tr>
	              	<tr>
	              		<td>余额</td>
	              		<td>
	              		<span>${data.u_money}</span>
	              		</td>
	              	</tr>
        	   `
        		   $("tbody").html(bodys);
           },'json');
    }
fun1();
function update(){
	//<form action="/Shopx/UserServlet?action=updateUser" method="post">
	var username = $("#name").val();   
	var phone = $("#phone").val(); 
	var addr = $("#addr").val(); 
	console.log("username"+username);
	console.log("phone"+phone);
	console.log("addr"+addr);
	if(username==="" && addr==="" && phone==="" ){
		alert('请输入信息');
	}else if(username===""){
		alert('请输入用户名');
	}else if(phone===""){
		alert('请输入电话号码');
	}else if(addr===""){
		alert('请输入地址');
	}else{
		//进行ajax交互
		 $.ajax({
				method:'get',
				data:{'username':username,'addr':addr,"phone":phone},
				url:'/Shopx/UserServlet?action=updateUser',
				success:function(data){
					if(data>0){
						alert('修改成功');
						window.close();
						history.back();
					}else if(data===0){
						alert('修改失败，电话号码或者用户名已存在');
					}
				},
				dataType:'json'
            });
	}
	
}

</script>
</body>
</html>